

package com.bei_en.teacher.management.service.system;

import java.util.ArrayList;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.bei_en.teacher.management.model.system.bean.SystemLogs;
import com.bei_en.teacher.management.model.system.condition.SystemLogsCondition;
import com.bei_en.teacher.management.model.system.vo.SystemLogsVo;
import com.bei_en.teacher.management.persistence.dao.system.SystemLogsDao;
import com.bei_en.teacher.management.service.BaseService;

/**
 *
 * @author Longqs
 * @date 2016-6-15 11:43:10
 */
@Transactional(rollbackFor = Exception.class)
@Service
public class SystemLogsService extends BaseService{

    @Autowired
    private SystemLogsDao systemLogsDao;

    public void insert(SystemLogsVo model) {

    	 systemLogsDao.insert(model.getSystemLogs());
    }

//    /**
//     * 插入并返回生成的id
//     * @param model
//     * @return
//     */
//    public Integer merge(SystemLogsVo model) {
//
//	systemLogsDao.insert(model.getSystemLogs());
//	return systemLogsDao.findLastInsertedId();
//
//    }

    public void delete(Integer modelInteger) {

    	systemLogsDao.delete(modelInteger);
    }

    public SystemLogsVo findById(Integer modelInteger) {

    	SystemLogsVo model = new SystemLogsVo(systemLogsDao.findById(modelInteger));
    	return model;
    }

    public void update(SystemLogsVo model) {

    	systemLogsDao.update(model.getSystemLogs());
    }

    /**
     * 动态更新,只更新非null的值
     * @param model
     */
    public void updateSelective(SystemLogsVo model) {

    	systemLogsDao.updateSelective(model.getSystemLogs());
    }

    public int countAll() {

    	return systemLogsDao.countAll();
    }

    public List<SystemLogsVo> findAll() {

		List<SystemLogsVo> list = new ArrayList<SystemLogsVo>();
		List<SystemLogs> list1 = systemLogsDao.findAll();
		for (SystemLogs model : list1) {
		    list.add(new SystemLogsVo(model));
		}
		return list;
    }

    public List<Integer> findAllIds() {

    	return systemLogsDao.findAllIds();
    }

    /**
     * 分页查询，包括总数和内容
     * @param Vo  返回总数
     * @return  返回内容
     */
    public List<SystemLogsVo> findSystemLogsPage(SystemLogsCondition vo) {

		Integer totalCount = searchSystemLogsNum(vo);
		List<SystemLogsVo> list = new ArrayList<SystemLogsVo>();
		vo.setTotalCount(totalCount);

		if (totalCount>0) {
		    vo.setOrderField(vo.getOrderField()!=null ? vo.getOrderField() : "id");
		    vo.setOrderDirection(vo.getOrderDirection()!=null ? vo.getOrderDirection() : "desc");

		    RowBounds rb = new RowBounds(vo.getStartIndex(), vo.getPageSize());
		    List<SystemLogs> list1 = systemLogsDao.findPageBreakByCondition(vo, rb);
		    for (SystemLogs model : list1) {
		    	list.add(new SystemLogsVo(model));
		    }

		}

		return list;
    }

    private Integer searchSystemLogsNum(SystemLogsCondition Vo) {

    	return systemLogsDao.findNumberByCondition(Vo);
    }

}
